﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using CoolCode.Ioc;
using CoolCode.Web;
using CoolCode.Web.Security;
using CoolCode.Data;
using CoolCode.Data.Linq;
using CoolCode.Services;
//using CoolCode.Bracket.LinqToEntity.Services;
using CoolCode.Bracket.LinqToSql.Services;
using XNoteBook.Services;
using XNoteBook.Services.Implement; 

namespace XNoteBook.UI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
				//,new { id = @"[\w]{0,50}" } //限定id最大长度是50
            );

			routes.MapRoute(
				"User",                                               
				"{controller}/{action}/{user}",                            
				new { controller = "User", action = "Index", user = "" }   
			);
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

			RegisterServices(InjectTable.Injector);

			DataContextProxy.Instance.Register(typeof(XDataContext));
        }

		private static void RegisterServices(Injector injector)
		{
			//Common
			injector.Link<ITrackService, TrackService>();
			injector.Link<IMenuService, MenuService>();
			injector.Link<IMembership, DefaultMembership>();
			injector.Link<IFormsAuthentication, DefaultFormsAuthentication>();
			//Customerize
			injector.Link<IPostService, PostService>();
			injector.Link<ICommonService, CommonService>(); 
			
		}
    }
}